﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SiteManager.Models;
using AppCms.Core.Configs;
using System.Web.Mvc;

namespace SiteManager.Core
{
    public enum SelectType
    {
        /// <summary>
        /// 模板
        /// </summary>
        Theme,
        /// <summary>
        /// 语言
        /// </summary>
        Language
    }

    public class Utils
    {
        /// <summary>
        /// 获取Session中登陆成功的管理员
        /// </summary>
        /// <returns></returns>
        public static admins GetAdmin()
        {
            if (HttpContext.Current.Session[Names.SESSION_ADMIN_NAME] == null)
                return null;

            return HttpContext.Current.Session[Names.SESSION_ADMIN_NAME] as admins;
        }

        /// <summary>
        /// 设置登陆成功的管理员到Session中
        /// </summary>
        /// <param name="admin"></param>
        public static bool SetAdmin(admins admin)
        {
            if (admin == null)
            {
                HttpContext.Current.Session[Names.SESSION_ADMIN_NAME] = null;
                return true;
            }
            if (admin.AdminID < 1)
                return false;

            HttpContext.Current.Session[Names.SESSION_ADMIN_NAME] = admin;
            return true;
        }

        /// <summary>
        /// 返回主题集合，每个数据为主题的名字
        /// </summary>
        public static Dictionary<string, string> ThemeList
        {
            get
            {
                Dictionary<string, string> themes = new Dictionary<string, string>();
                themes.Add("Chromatron", "默认模板");
                themes.Add("TestTheme", "测试模板");
                return themes;
            }
        }

        /// <summary>
        /// 返回语言集合，每个数据为语言的名字
        /// </summary>
        public static Dictionary<string, string> LanguageList
        {
            get
            {
                Dictionary<string, string> languages = new Dictionary<string, string>();
                languages.Add("简体中文", "zh-cn");
                languages.Add("日本人语", "jp");
                languages.Add("zh-cn", "简体中文");
                languages.Add("jp", "日本人语");
                return languages;
            }
        }

        public static SelectList SelectList(SelectType selectType)
        {
            return SelectList(selectType, null);
        }

        public static SelectList SelectList(SelectType selectType, object selectValue)
        {
            SelectList selectList = null;
            switch (selectType)
            {
                default:
                    return null;

                case SelectType.Theme:
                    selectList = new SelectList(ThemeList, "Value", "Key", selectValue);
                    break;

                case SelectType.Language:
                    selectList = new SelectList(LanguageList, "Value", "Key", selectValue);
                    break;

            }
            return selectList;
        }


    }
}